<script lang="ts">
import { ref } from 'vue'
import CompanyInfo from '../components/CompanyInfo.vue'
import UserInfo from '../components/UserInfo.vue'
import { useRouter } from 'vue-router'
import { onMounted } from 'vue'

export default {
  setup() {
    const router = useRouter()

    const getLinkParams = (itemCode: string, callback: any) => {
      ihgAppJssdk.notice.showPreloader({
        text: '使劲加载中..'
      })
      ihgAppJssdk.network.request({
        url:
          'https://policy.ihuanggang.cn/policy-dispense/queryBusi/queryQrsConfInfo?itemCode=' +
          itemCode,
        method: 'get',
        data: {},
        headers: {
          app_type: '2'
        },
        success: function (data: { code: number; data: any }) {
          ihgAppJssdk.notice.hidePreloader()
          if (data.code == 200) {
            callback(data.data)
          }
        },
        fail: function (res: any) {
          ihgAppJssdk.notice.hidePreloader()
          console.log(res)
        }
      })
    }
    const generateCurrentTimestamp = () => {
      const now = new Date()
      const year = now.getFullYear().toString().padStart(4, '0')
      const month = (now.getMonth() + 1).toString().padStart(2, '0') // 注意月份需要加1，因为JavaScript中getMonth()返回的是0-11
      const day = now.getDate().toString().padStart(2, '0')
      const hour = now.getHours().toString().padStart(2, '0')
      const minute = now.getMinutes().toString().padStart(2, '0')
      const second = now.getSeconds().toString().padStart(2, '0')

      return `${year}${month}${day}${hour}${minute}${second}`
    }
    const generateCurrentTime = () => {
      const now = new Date()
      const year = now.getFullYear().toString().padStart(4, '0')
      const month = (now.getMonth() + 1).toString().padStart(2, '0') // 注意月份需要加1，因为JavaScript中getMonth()返回的是0-11
      const day = now.getDate().toString().padStart(2, '0')
      const hour = now.getHours().toString().padStart(2, '0')
      const minute = now.getMinutes().toString().padStart(2, '0')
      const second = now.getSeconds().toString().padStart(2, '0')

      return `${year}-${month}-${day} ${hour}:${minute}:${second}`
    }

    const onSubmit = (values: any) => {
      console.log('submit', values)

      getLinkParams('11421100011250064702', (query: any) => {
        console.log(query)
        const time = generateCurrentTimestamp()
        ihgAppJssdk.network.request({
          url: query.zc_saveinfo,
          method: 'post',
          data: {
            zc_appkey: query.zc_appkey,
            zc_zdydata: query.zc_zdydata,
            zc_sign_time: query.zc_sign_time,
            zc_sign: query.zc_sign,
            zc_version: query.zc_version,
            zc_saveinfo: {
              zcbjbm: '',
              status: '1',
              createtime: generateCurrentTime(),
              itemcode: query.zc_appkey,
              itemname: '返乡创业一次性补贴',
              businessIdentify: '301b67cdd92c524cb580e48d30e8a384'
            }
          },
          headers: {
            'Content-Type': 'application/json;charset=utf-8',
            'x-hg-api-key': '73b6ddf1-e7f7-4e9b-96b9-ed39d758cb2e'
          },
          success: function (res: any) {
            console.log(res)

            let bmbmb = res.data

            // ihgAppJssdk.network.request({
            //   url: query.zc_resultinfo,
            //   method: 'post',
            //   data: {
            //     zc_appkey: query.zc_appkey,
            //     zc_zdydata: query.zc_zdydata,
            //     zc_sign_time: query.zc_sign_time,
            //     zc_sign: query.zc_sign,
            //     zc_version: query.zc_version,
            //     zc_resultinfo: {
            //       zcbjbm: res.data,
            //       itemcode: query.zc_appkey,
            //       itemname: '返乡创业一次性补贴',
            //       blr: '测试',
            //       bjrq: generateCurrentTime(),
            //       bjzt: '83',
            //       qhdm: '000000000000',
            //       jgdm: '987654321987654321',
            //       type: '3',
            //       bjyj: '测试',
            //       jgfj: "[{'materialGUID':'政策共享材料库ID或本地存储的文件下载路径','name':'附件名称','materialExplain':'3','remark':'备注','materialType':'2'}]",
            //       jgms: '1'
            //     }
            //   },
            //   headers: {
            //     'Content-Type': 'application/json;charset=utf-8'
            //   },
            //   success: function (res: any) {
            //     console.log(res)
            //     ihgAppJssdk.operateWindow.zcResult({
            //       zcbjData: {
            //         zcbjbm: bmbmb,
            //         xmmc: '返乡创业一次性补贴'
            //       }
            //     })
            //   }
            // })
          }
        })
      })
    }
    const onFailed = (errorInfo: any) => {
      console.log('failed', errorInfo)
    }
    onMounted(() => {})
    return { onSubmit, onFailed }
  }
}
</script>

<template>
  <van-form @submit="onSubmit" @failed="onFailed" scroll-to-error>
    <a-layout style="padding: 8px; background-color: white">
      <a-layout-content style="padding: 0; width: 100%; margin-bottom: 6rem">
        <!-- 政策解读 -->
        <!-- <a-card title="申报指南" style="width: 100%">
          <p>
            返乡创业补贴指各类返乡创业人员5年内在本地首次创业办理注册登记，自登记日起正常经营6个月及以上、带动就业3人及以上的，给予5000元的一次性创业补贴，已享受过其他一次性创业补贴的除外。
          </p>
        </a-card>
        <a-card title="申报材料" style="width: 100%">
          <p>1.一次性创业补贴申请表；</p>
          <p>2.申请人身份证；</p>
          <p>3.工商营业执照；</p>
          <p>
            4.返乡人员外出证明材料（真实反映外出的各类证明，包括在外务工入职登记表、劳动合同、6个月及以上工资流水、6个月及以上工资转账记录、6个月及以上社保缴费记录、6个月及以上住房公积金缴费记录、6个月及以上纳税记录、外地注册营业执照、6个月及以上公司经营流水、外地暂住证、外地就业失业登记证、大学生外地大学的毕业证、退役士兵外地服兵役后的退役证等其中的一种即可）；
          </p>
          <p>5.带动就业证明材料（3名及以上员工身份证、与其签订的劳动合同及工资发放流水）；</p>
          <p>6.申请人的社会保障卡（补贴发放）。</p>
        </a-card> -->
        <a-divider>企业详情</a-divider>
        <CompanyInfo />
        <a-divider>申请人信息</a-divider>
        <UserInfo />
      </a-layout-content>
      <a-layout-footer
        :style="{
          height: '6rem',
          position: 'fixed',
          left: 0,
          right: 0,
          bottom: 0,
          backgroundColor: 'rgba(255, 255, 255, 0)'
        }"
      >
        <div style="margin: 5vw 0">
          <van-button
            round
            block
            type="primary"
            native-type="submit"
            style="
              background: linear-gradient(135deg, #ffb641 0%, #ff8300 100%);
              border: 0;
              font-size: 4vw;
            "
          >
            提交
          </van-button>
        </div>
      </a-layout-footer>
    </a-layout>
  </van-form>
</template>
